<?php
    /**
    * Get Video For Player
    * @author: trungdt
    * @since: Oct 27, 2011
    * @version: 1.0
    * 
    * Change logs
    * Oct 30, 2011 - trungdt - add support playlist return
    */

    if (!defined('EXPONENT')) exit('');
    $id="";
    if (isset($_REQUEST['id']))
    {
        $id=_ab_safe_html_string($_REQUEST['id']);
        $video=$db->selectObject("productsmodule_video", "seo_name = '{$id}'");
        if ($video)
        {
            // update views
            $video->views++;
            $db->updateObject($video,"productsmodule_video" );
            $video=productsmodule::__VideoProcess($video, true);
            $video=$video[0];
            echo json_encode($video);
        }
        else
            die();
    }
    else if (isset($_REQUEST['playlist_id']))
    {
        $id=intval($_REQUEST['playlist_id']);
        $video=$db->selectObjects("productsmodule_video","cat_id = {$id} ORDER BY postdate DESC");
        $video=productsmodule::__VideoProcess($video);
        $template=new template("productsmodule","_Video_Playlist",$loc);
        $template->assign("video", $video);
        $template->assign("video_count", count($video));
        echo $template->render();
    }
    exponent_theme_setFlagAjaxAction(true);
?>